package com.example.dmc_android_sellbreakfast_ver1;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class ShowInfoActivity extends Activity {
	Database mDatabase;
	private Button btn_edit;
	private TextView tv_user, tv_name, tv_numberRoom;
	String id1, pw1;

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.layout_infor_user);
		mDatabase = new Database(this);
		Bundle data_recive = getIntent().getExtras();
		id1 = data_recive.getString("id_user");
		pw1 = data_recive.getString("pw_user");
		Toast.makeText(this, "user = " + id1 + "\n" + "password = " + pw1, 1000)
				.show();
		init();
		handle();
		ShowAllInfo();
	}

	private void ShowAllInfo() {
		// TODO Auto-generated method stub
		// String id = "quangdao";
		// String pw = "quangdao";
		mDatabase.open();
		String name = mDatabase.getName(id1, pw1);
		String account = mDatabase.getAccount(id1, pw1);
		String numberRoom = mDatabase.getNumberRoom(id1, pw1);
		tv_name.setText(name);
		tv_numberRoom.setText(numberRoom);
		tv_user.setText(account);
		mDatabase.close();
	}

	private void init() {
		// TODO Auto-generated method stub
		btn_edit = (Button) findViewById(R.id.btn_edit);
		tv_name = (TextView) findViewById(R.id.tv_edit_name);
		tv_numberRoom = (TextView) findViewById(R.id.tv_edit_numberRoom);
		tv_user = (TextView) findViewById(R.id.tv_edit_user);
	}

	private void handle() {
		// TODO Auto-generated method stub
		btn_edit.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent mIntent = new Intent(v.getContext(),
						EditInforActivity.class);
				mIntent.putExtra("account", id1);
				mIntent.putExtra("password", pw1);
				startActivity(mIntent);
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.action_bar, menu);
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// TODO Auto-generated method stub
		switch (item.getItemId()) {
		case R.id.itProfile:
			Intent mIntent = new Intent(this, ShowInfoActivity.class);
			Bundle data_recive = getIntent().getExtras();
			String id_user = null,
			pw_user = null;
			if (data_recive != null) {
				id_user = data_recive.getString("id_user");
				pw_user = data_recive.getString("pw_user");
				Toast.makeText(this,
						"da goi dc buoc 1" + id_user + "\n" + pw_user, 1000)
						.show();
			}
			mIntent.putExtra("id_user", id_user);
			mIntent.putExtra("pw_user", pw_user);
			startActivity(mIntent);
			return true;
		case R.id.itBack:
			onBackPressed();
			return true;
		case R.id.itLogout:
			Intent mIntent1 = new Intent(this, MainActivity.class);
			startActivity(mIntent1);
		}
		return false;
	}

	@Override
	public void onBackPressed() {
		// TODO Auto-generated method stub

		super.onBackPressed();
	}
}
